package com.woniuxy.credit_loans.interceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author Cornelia
 * @Date 2022-12-12
 * @Description  自定义拦截器实现用户日志登录  --马玉雪 2022-12-12
 **/
@Component
public class LogInterceptor implements HandlerInterceptor {

    //通过interceptor获取到客户端点请求的ip地址，放到Treadlocal中，再在切面将ip取出来
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String ip = request.getRemoteAddr();
        ThreadLocal<Object> objectThreadLocal = new ThreadLocal<>();
        objectThreadLocal.set(ip);
        return true;
    }
}
